package features.advance.leetcode.array.easy;

/**
 * @author LIN
 * @date 2021-05-26
 */
public class Offer53_1 {

    public static void main(String[] args) {
        Solution solution = new Solution() {
            @Override
            public int search(int[] nums, int target) {
                if (nums.length == 0) return 0;
                int max = 100000;
                int[] countPositive = new int[max];
                int[] countNegative = new int[max];
                for (int num : nums) {
                    if (num >= 0)
                        countPositive[num]++;
                    else
                        countNegative[Math.abs(num)]++;
                }

                if (target >= 0)
                    return countPositive[target];
                else
                    return countNegative[Math.abs(target)];
            }
        };
        int[] nums = {1,2,3,4,5,6,6,6,6,6,7,8,9};
        int target = 6;

    }

    static class Solution{

        public int search(int[] nums, int target){
            int res = 0;
            if(nums == null || nums.length < 1){
                return res;
            }
            for (int i = 0; i < nums.length; i++) {
                if(target == nums[i]){
                    res++;
                }
                if(nums[i] > target){
                    return res;
                }
            }
            return res;
        }
    }
}



